package com.qubuyer.core.utils

import android.app.Activity
import android.content.res.Resources
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.WindowManager

/**
 * Author: linwg
 * Time: 2021/2/25 0025
 * Description:
 */
class StatusBarUtil {
    companion object{
        fun transparentStatusBar(activity: Activity) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                activity.window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
                activity.window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                activity.window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
                activity.window.statusBarColor = Color.TRANSPARENT
            }
        }

        fun getStatusBarHeight(): Int {
            var result = 0
            try {
                val resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android")
                if (resourceId > 0) {
                    result = Resources.getSystem().getDimensionPixelSize(resourceId)
                }
            } catch (e: Resources.NotFoundException) {
                e.printStackTrace()
            }
            return result
        }
    }
}